package com.cloudsigns.factorymanager2.project.presenter;

import android.os.Handler;

import com.cloudsigns.factorymanager2.produce.bean.ProduceProduceOrderBean;
import com.cloudsigns.factorymanager2.project.iview.IGetProduceOrderListView;
import com.cloudsigns.factorymanager2.project.model.GetProduceOrderListModel;
import com.cloudsigns.factorymanager2.project.model.IGetProduceOrderListModel;

import java.util.List;

public class GetProductOrderListPresenter {
    private IGetProduceOrderListView view;
    private IGetProduceOrderListModel model;
    private Handler mHandler = new Handler();

    public GetProductOrderListPresenter(IGetProduceOrderListView view) {
        this.view = view;
        this.model = new GetProduceOrderListModel();
    }

    public void getProdectOrderList() {

        model.getProductOrderList(new GetProduceOrderListModel.OnProductOrderListListener() {
            @Override
            public void getDataSuccessed(final List<ProduceProduceOrderBean> produceOrderBeanList) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getDataSuccessed(produceOrderBeanList);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void getDataFailed(final String desc) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.showFailedError(desc);
                        view.hideLoading();
                    }
                });
            }
        });
    }
}
